package servlet;

import service.GoodsService;
import model.Goods;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "goods_delete",urlPatterns = "/goods_delete")//用户订单删除商品
public class GoodsDeleteServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        GoodsService gService = new GoodsService();
        int goodsid = Integer.parseInt(request.getParameter("id"));
        gService.delete(goodsid);

        List<Goods> goodslist= gService.GetAllProducts();
        this.getServletContext().removeAttribute("goodsList");
        this.getServletContext().setAttribute("goodsList",goodslist);
        response.sendRedirect(request.getContextPath() + "/history_goods_publish.jsp");
//        request.getRequestDispatcher("/history_goods_publish.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
